<template>
	<view class="container">
		<view class="tui-box">
			<tui-list-cell :arrow="true" unlined :radius="true">
				<view class="tui-address">
					<view v-if="address" @click="addressList">
						<view class="tui-userinfo">
							<text class="tui-name">{{address.addressee}}</text>{{address.mobile}}
						</view>
						<view class="tui-addr">
							<view class="tui-addr-tag">家</view>
							<text>{{address.address}}</text>
						</view>
					</view>
					<view class="tui-none-addr" v-else @click="chooseAddr">
						<image src="/static/images/index/map.png" class="tui-addr-img" mode="widthFix"></image>
						<text>选择收货地址</text>
					</view>
				</view>
				<view class="tui-bg-img"></view>
			</tui-list-cell>
			<view class="tui-top tui-goods-info">
				<tui-list-cell :hover="false" :lineLeft="false">
					<view class="tui-goods-title">
						商品信息
					</view>
				</tui-list-cell>
			
					<block>
						<tui-list-cell :hover="false" padding="0">
							<view class="tui-goods-item">
								<image :src="products.pic_cover_big" class="tui-goods-img"></image>
								<view class="tui-goods-center">
									<view class="tui-goods-name">{{products.goods_name}}</view>
									<view class="tui-goods-attr"></view>
								</view>
								<view class="tui-price-right">
									<view>￥{{products.price}}</view>
									<view>x1</view>
								</view>
							</view>
						</tui-list-cell>
					</block>
				

				<tui-list-cell :hover="false">
					<view class="tui-padding tui-flex">
						<view>商品总额</view>
						<view>￥{{products.price}}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false">
					<view class="tui-padding tui-flex">
						<view>配送费</view>
						<view>￥0</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" :lineLeft="false" padding="0">
					<view class="tui-remark-box tui-padding tui-flex">
						<view>订单备注</view>
						<input type="text" class="tui-remark" placeholder="选填: 请先和商家协商一致"
							placeholder-class="tui-phcolor"></input>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" unlined>
					<view class="tui-padding tui-flex tui-total-flex">
						<view class="tui-flex-end tui-color-red">
							<view class="tui-black">合计： </view>
							<view class="tui-size-26">￥</view>
							<view class="tui-price-large">0</view>
							<view class="tui-size-26">.00</view>
						</view>
					</view>
				</tui-list-cell>
			</view>
		</view>
		<view class="tui-safe-area"></view>
		<view class="tui-tabbar">
			<view class="tui-flex-end tui-color-red tui-pr-20">
				<view class="tui-black">实付金额: </view>
				<view class="tui-size-26">￥</view>
				<view class="tui-price-large">{{totalPrice}}</view>
				<view class="tui-size-26">0.00</view>
			</view>
			<view class="tui-pr25">
				<tui-button width="200rpx" height="70rpx" :size="28" type="warning" shape="circle" @click="btnPay">提交订单
				</tui-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				hasCoupon: true,
				insufficient: false,
				show: false,
				shows: false,
				shopsMsg: '',
				address: '',
				products: [{
					pic_cover_small: ''
				}],
				buyer_message: '',
				address_id: '',
				totalFee: '',
				totalPrice: '',
				defaultAddress: '0',
				balance: '',
				isDoRefresh: '',
				shipping_fee: '',
				method: '',
				out_trade_no: '',
				cart: false,
				cart_arr: '',
				total_delivery_money: '',
				total_xfmoney: '',
				order_id:''
			}
		},
		onShow: function(e) {
			let pages = getCurrentPages();
		 let currPage = pages[pages.length - 1];
			if (this.isDoRefresh == true) {
				this.isDoRefresh = false;
				this.init();
			}
		},
		onLoad(options) {
			this.tui.haslogin();
			if (options.order_id) {
				this.order_id=options.order_id
				if (this.tui.isLogin()) {
					this.init()
				}
			}


		},
		methods: {
			setData(isDoRefresh) {
				this.isDoRefresh = true;
			},
			chooseAddr() {
				uni.navigateTo({
					url: "/pageschild/editAddress/editAddress"
				})
			},
			addressList() {
				uni.navigateTo({
					url: "/pageschild/address/address"
				})
			},
			init() {
				let token = this.tui.getToken();
				let datas = {
					token: token,
					address_id: 'is_default'
				};
				// #ifdef H5
				// let ua = window.navigator.userAgent.toLowerCase()
				// if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				// 	this.iswx = true;
				// }
				//#endif
				let address = this.tui.request('user', 'post', datas, 1000, 1, '', 'address');
				Promise.resolve(address).then((value) => {
					if (value.code == 10000) {
						this.address = value.data[0];
						if (value.data) {
							value.data.forEach((item, index) => {
								if (item.is_default == 1) {
									this.defaultAddress = item;
								}
							})
							if (!this.defaultAddress) {
								this.defaultAddress = value.data[0]
							}
						}
					} else {
						this.tui.toast(value.message);
					}
				})
				let bdatas = {
					token: token,
					order_id: this.order_id,
					
				};
				let boxInfo = this.tui.request('box', 'post', bdatas, 1000, 1, '', 'getBoxInfo');
				Promise.resolve(boxInfo).then((value) => {
					if (value.code == 10000) {
						if (value.data) {
							this.products=value.data
						}
					} else {
						this.tui.toast(value.message);
					}
				})
			},
			btnPay() {
				//先申请下单数据
				let token = this.tui.getToken();
				let obj = {
					token: token,
					address_id:this.defaultAddress.id,
					order_id:this.order_id,
					buyer_message:this.buyer_message
				}
				this.method = 'submitBoxOrders';
				let addOrder = this.tui.request('order', 'post', obj, 1000, 1, '', this.method);
				Promise.resolve(addOrder).then((value) => {
					if (value.code == 10000) {
						uni.navigateTo({
							url: "../success/success?out_trade_no=" + value.data.out_trade_no
						})
					} else {
						this.tui.toast(value.message);
					}
				})
			},
			delCart() {
				let token = this.tui.getToken();
				let datas = {
					token: token,
					cart_ids: this.cart_arr
				};
				let delaCart = this.tui.request('goods', 'post', datas, 1000, 1, '', 'delCart');
				Promise.resolve(delaCart).then((value) => {

				})
			},
			popupClose() {
				this.show = false
			}
		}
	}
</script>

<style>
	.container {
		padding-bottom: 98rpx;
	}

	.tui-box {
		padding: 20rpx 0 118rpx;
		box-sizing: border-box;
	}

	.tui-address {
		min-height: 80rpx;
		padding: 10rpx 0;
		box-sizing: border-box;
		position: relative;
	}

	.tui-keyboard-tips {
		width: 100%;
		height: 120rpx;
		line-height: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		background: #fff;
		position: relative;
		color: #333;
		border: 0;
	}

	.tui-userinfo {
		font-size: 30rpx;
		font-weight: 500;
		line-height: 30rpx;
		padding-bottom: 12rpx;
	}

	.tui-name {
		padding-right: 40rpx;
	}

	.coin-nums {
		color: #f5b82b;
		font-weight: bold;
	}

	.tui-addr {
		font-size: 24rpx;
		word-break: break-all;
		padding-right: 25rpx;
	}

	.tui-addr-tag {
		padding: 5rpx 8rpx;
		flex-shrink: 0;
		background: #EB0909;
		color: #fff;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		font-size: 25rpx;
		line-height: 25rpx;
		transform: scale(0.8);
		transform-origin: 0 center;
		border-radius: 6rpx;
	}

	.tui-bg-img {
		position: absolute;
		width: 100%;
		height: 8rpx;
		left: 0;
		bottom: 0;
		background: url("") repeat;
	}

	.tui-top {
		margin-top: 20rpx;
		overflow: hidden;
	}

	.tui-goods-title {
		font-size: 28rpx;
		display: flex;
		align-items: center;
	}

	.tui-padding {
		box-sizing: border-box;
	}

	.tui-goods-item {
		width: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
	}

	.tui-goods-img {
		width: 180rpx;
		height: 180rpx;
		display: block;
		flex-shrink: 0;
	}

	.tui-goods-center {
		flex: 1;
		padding: 20rpx 8rpx;
		box-sizing: border-box;
	}

	.tui-goods-name {
		max-width: 310rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 26rpx;
		line-height: 32rpx;
	}

	.tui-goods-attr {
		font-size: 22rpx;
		color: #888888;
		line-height: 32rpx;
		padding-top: 20rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.tui-price-right {
		text-align: right;
		font-size: 24rpx;
		color: #888888;
		line-height: 30rpx;
		padding-top: 20rpx;
	}

	.tui-flex {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 26rpx;
	}

	.tui-total-flex {
		justify-content: flex-end;
	}

	.tui-color-red,
	.tui-invoice-text {
		color: #E41F19;
		padding-right: 30rpx;
	}

	.tui-balance {
		font-size: 28rpx;
		font-weight: 500;
	}

	.tui-black {
		color: #222;
		line-height: 30rpx;
	}

	.tui-gray {
		color: #888888;
		font-weight: 400;
	}

	.tui-light-dark {
		color: #666;
	}

	.tui-goods-price {
		display: flex;
		align-items: center;
		padding-top: 20rpx;
	}

	.tui-size-26 {
		font-size: 26rpx;
		line-height: 26rpx;
	}

	.tui-price-large {
		font-size: 34rpx;
		line-height: 32rpx;
		font-weight: 600;
	}

	.tui-flex-end {
		display: flex;
		align-items: flex-end;
		padding-right: 0;
	}

	.tui-phcolor {
		color: #B3B3B3;
		font-size: 26rpx;
	}

	/* #ifndef H5 */
	.tui-remark-box {
		padding: 22rpx 30rpx;
	}

	/* #endif */
	/* #ifdef H5 */
	.tui-remark-box {
		padding: 26rpx 30rpx;
	}

	/* #endif */

	.tui-remark {
		flex: 1;
		font-size: 26rpx;
		padding-left: 64rpx;
	}

	.tui-scale-small {
		transform: scale(0.8);
		transform-origin: 100% center;
	}

	.tui-scale-small .wx-switch-input {
		margin: 0 !important;
	}

	/* #ifdef H5 */
	>>>uni-switch .uni-switch-input {
		margin-right: 0 !important;
	}

	/* #endif */
	.tui-tabbar {
		width: 100%;
		height: 98rpx;
		background: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 26rpx;
		box-shadow: 0 0 1px rgba(0, 0, 0, .3);
		padding-bottom: env(safe-area-inset-bottom);
		z-index: 996;
	}

	.tui-pr-30 {
		padding-right: 30rpx;
	}

	.tui-pr-20 {
		padding-right: 20rpx;
	}

	.tui-none-addr {
		height: 80rpx;
		padding-left: 5rpx;
		display: flex;
		align-items: center;
	}

	.tui-addr-img {
		width: 36rpx;
		height: 46rpx;
		display: block;
		margin-right: 15rpx;
	}


	.tui-pr25 {
		padding-right: 25rpx;
	}

	.tui-safe-area {
		height: 1rpx;
		padding-bottom: env(safe-area-inset-bottom);
	}
</style>
